package Classes.GameViews.ViewPanels
{
	import Classes.GameDatas.GD_Player;
	import Classes.GameDatas.GD_Shop;
	import Classes.GameViews.ViewScenes.VS_Main;
	import Classes.Managers.M_ConfigData;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.system.ApplicationDomain;

	/**
	 *金币兑换类 
	 * @author 邓坚
	 * 
	 */	
	public class VP_exChangePanel extends ViewPanel
	{
		private static var _instance:VP_exChangePanel;
		private var _interfaceUI:Sprite;
		private var _shops:Array;
//		private var _ratio:Number;			//金币与o币对兑率   比如1000 就是1欧等于1000金币
		
		public function VP_exChangePanel()
		{
			init();
		}
		
		public function init():void
		{
			_interfaceUI=new (ApplicationDomain.currentDomain.getDefinition("PanelExChange_v") as Class);
			this.addChild(this._interfaceUI);
			addListener();
		}
		
		public function addListener():void
		{
			this.addEventListener("close",closeHandler);
			this.addEventListener("btn1Click",onClick);
			this.addEventListener("btn2Click",onClick);
			this.addEventListener("btn3Click",onClick);
			this.addObserveFunc(GD_Player.instance,"QQVip",controlMoenyIcon);
		}
		
		public function controlMoenyIcon():void
		{
			this._interfaceUI["controlMoenyIcon"](M_ConfigData.instance.isOpenQQVip);
		}
		
		/**
		 *点击了 
		 * @param e
		 * 
		 */
		public function onClick(e:Event):void
		{
			switch(e.type){
				case "btn1Click":
					VP_TextWinPanel.instance.openTextWindon("确认兑换","确认以"+_shops[0]["price"]+"欧币兑换"+_shops[0]["perNum"]+"金币",this._interfaceUI["sendBuyCommand1"]);
					break;
				case "btn2Click":
					VP_TextWinPanel.instance.openTextWindon("确认兑换","确认以"+_shops[1]["price"]+"欧币兑换"+_shops[1]["perNum"]+"金币",this._interfaceUI["sendBuyCommand2"]);
					break;
				case "btn3Click":
					VP_TextWinPanel.instance.openTextWindon("确认兑换","确认以"+_shops[2]["price"]+"欧币兑换"+_shops[2]["perNum"]+"金币",this._interfaceUI["sendBuyCommand3"]);
					break;
			}
		}
		
		/**
		 *打开兑换面板 
		 * 
		 */
		public function openPanel():void
		{
			this.openAt(VS_Main.instance,true);
			setData(new Array);
			this.toCenter();
			this._shops		=	_interfaceUI["filterData"](GD_Shop.instance.shopItems);
		}
		
		/**
		 *关闭兑换面板 
		 * @param e
		 * 
		 */
		public function closeHandler(e:Event):void
		{
			this.close();
		}
		
		/**
		 *设置数据 
		 * @param shops
		 * 
		 */
		public function setData(shops:Array):void
		{
			_interfaceUI["setAllData"](GD_Shop.instance.shopItems);
		}
	

		
		public static function get instance():VP_exChangePanel
		{
			if(!_instance)_instance=new VP_exChangePanel();
			return _instance;
		}
		
		public function get interfaceUI():Sprite
		{
			return _interfaceUI;
		}
	}
}